package com.cdtye.itps.cms.service.datasysn;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cdtye.common.mybatiscore.base.BaseService;
import com.cdtye.itps.cms.dao.detect.JcjcDefectInfoSection;
import com.cdtye.itps.cms.mapper.defect.JcjcDefectInfoSectionMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class JcjcDefectInfoService extends BaseService<JcjcDefectInfoSectionMapper, JcjcDefectInfoSection> {
    @Autowired
    private JcjcDefectInfoSectionMapper jcjcDefectInfoSectionMapper;

    @DS("tmis")
    public boolean insertDefectInfoTmis(JcjcDefectInfoSection jcjcDefectInfoSection){
        return this.saveOrUpdate(jcjcDefectInfoSection);
    }

    @DS("tmis")
    public List<JcjcDefectInfoSection> selectIdDefectInfoTmis(JcjcDefectInfoSection jdis){
        if (StringUtils.isBlank(jdis.getDiscoverSourceId())) {
            return null;
        }
        QueryWrapper<JcjcDefectInfoSection> queryWrapper = new QueryWrapper<>();
//        queryWrapper.and(wrapper  -> wrapper.eq("DEL_FLAG", DelFlagEnum.NO).or().isNull("DEL_FLAG"));
        queryWrapper.eq("discover_source_id", jdis.getDiscoverSourceId());
        List<JcjcDefectInfoSection> list = jcjcDefectInfoSectionMapper.selectList(queryWrapper);
//        if (CollectionUtils.isEmpty(list)) {
//            if (StringUtils.isNotBlank(jdis.getPillarId()) && null != jdis.getDiscoverDate() && StringUtils.isNotBlank(jdis.getDefectTypeId())) {
//                queryWrapper = new QueryWrapper<>();
//                queryWrapper.and(wrapper  -> wrapper.eq("DEL_FLAG", DelFlagEnum.NO).or().isNull("DEL_FLAG"));
//                queryWrapper.eq("pillar_id",jdis.getPillarId());
//                queryWrapper.eq("discover_date",jdis.getDiscoverDate());
//                queryWrapper.eq("defect_type_id",jdis.getDefectTypeId());
//                queryWrapper.eq("create_datetime_source",jdis.getCreateDatetimeSource());
//                if (StringUtils.isNotBlank(jdis.getDefectGradeId())) {
//                    queryWrapper.eq("defect_grade_id",jdis.getDefectGradeId());
//                }
//                list = jcjcDefectInfoMapper.selectList(queryWrapper);
//            }
//        }
        return list;
    }

    @DS("tmis")
    public int updateDefectInfoTmis(JcjcDefectInfoSection jdis){
        UpdateWrapper<JcjcDefectInfoSection> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("defect_info_id",jdis.getDefectInfoId());
        return jcjcDefectInfoSectionMapper.update(jdis,updateWrapper);
    }



}
